package xyz.eden.gateway.springcloud.admin.util;

import com.alibaba.fastjson2.JSON;
import org.springframework.http.server.reactive.ServerHttpResponse;
import reactor.core.publisher.Mono;
import xyz.eden.gateway.springcloud.admin.proxy.ResultSet;

import java.nio.charset.Charset;

public class RequestUtils {

    public static Mono<Void> unauthorized(ServerHttpResponse serverHttpResponse, ResultSet resultWrapper) {
        serverHttpResponse.getHeaders()
                .add("Content-Type", "application/json;charset=UTF-8");
        byte[] data = JSON.toJSONString(resultWrapper)
                .getBytes(Charset.defaultCharset());
        return serverHttpResponse.writeWith(Mono.just(serverHttpResponse.bufferFactory()
                .wrap(data)));
    }
}
